package com.codefish.codefishseckill.utils;

import cn.hutool.core.io.IoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * 读写工具
 *
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/09/14 上午 11:06
 */
@Slf4j
public class MyIoUtils {
    public static String readFromClasspath(String classpath) {
        ClassPathResource resource = new ClassPathResource(classpath);
        try (InputStream inputStream = resource.getInputStream()) {
            return IoUtil.read(inputStream, StandardCharsets.UTF_8);
        } catch (Exception e) {
            log.error("读取类路径文件[{}]失败", classpath);
        }
        return null;
    }
}
